﻿using AnimalEventTask;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AnimalTask.Tests
{
    [TestClass()]
    public class AnimalTest
    {
        [TestMethod()]        
        public void OnNameChangedTest()
        {
            Animal rabbit = new Animal("Zayo", "rabbit");
            string actualNewValue = string.Empty;
            string actualOldValue = string.Empty; 
            string expectedOldValue = "Zayo";
            string expectedNewValue = "Bayo";
            rabbit.NameChanged += new NameChangedEventHandler((s,e) => 
            { 
                actualNewValue = e.NewValue;
                actualOldValue = e.OldValue;
            });
            rabbit.Name = "Bayo";
            Assert.AreEqual(expectedNewValue, actualNewValue);
            Assert.AreEqual(expectedOldValue, actualOldValue);
            Assert.AreEqual(expectedNewValue, rabbit.Name);
        }

        [TestMethod()]
        public void NameChangeWithEqualValue()
        {
            Animal rabbit = new Animal("Zayo", "rabbit");
            bool eventRaised = false;
            rabbit.NameChanged += new NameChangedEventHandler((s, e) =>
            {
                eventRaised = true;
            });
            rabbit.Name = "Zayo";
            Assert.IsFalse(eventRaised);
        }
    }
}
